package han.chensing.latos.game.elements.character;

import com.badlogic.gdx.graphics.Color;

import javax.script.ScriptException;

public abstract class Character {

    public enum Type{
        Easy,Normal,Hard,Lunatic
    }
    protected String name;
    protected String description;
    protected byte[] image;
    protected Type type;
    protected float maxHealth;
    protected Color defaultHealthColor =Color.WHITE;
    protected Color defaultHurtColor =Color.RED;
    protected Color defaultBufferColor =Color.GRAY;

    public abstract void invokeTick(CharacterInstance characterInstance, float delta);

    public abstract void invokeMessage(CharacterInstance characterInstance, String message);

    public abstract boolean isDead(CharacterInstance characterInstance);

    public CharacterInstance genInstance() throws ScriptException {
        return new CharacterInstance(this);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public byte[] getImage() {
        return image;
    }

    public void setImage(byte[] image) {
        this.image = image;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public float getMaxHealth() {
        return maxHealth;
    }

    public void setMaxHealth(float maxHealth) {
        this.maxHealth = maxHealth;
    }

    public Color getDefaultHurtColor() {
        return defaultHurtColor;
    }

    public void setDefaultHurtColor(Color defaultHurtColor) {
        this.defaultHurtColor = defaultHurtColor;
    }

    public Color getDefaultHealthColor() {
        return defaultHealthColor;
    }

    public void setDefaultHealthColor(Color defaultHealthColor) {
        this.defaultHealthColor = defaultHealthColor;
    }

    public Color getDefaultBufferColor() {
        return defaultBufferColor;
    }

    public void setDefaultBufferColor(Color defaultBufferColor) {
        this.defaultBufferColor = defaultBufferColor;
    }

    protected void defaultBufferHealthHandle(CharacterInstance characterInstance,float delta){
        float bufferHealth = characterInstance.getBufferHealth();
        float health = characterInstance.health;
        bufferHealth=Math.max(0,bufferHealth);
        bufferHealth=Math.max(bufferHealth-(bufferHealth-health)*.05f,
                health);
        characterInstance.setBufferHealth(bufferHealth);
    }

    protected void defaultShownHealthHandle(CharacterInstance characterInstance,float delta){
        float shownHealth = characterInstance.getShownHealth();
        float health = characterInstance.health;
        shownHealth=Math.max(0,shownHealth);
        shownHealth=Math.min(shownHealth-(shownHealth-health)*.2f,
                health);
        characterInstance.setShownHealth(shownHealth);
    }

    protected void defaultHuntAlphaHandle(CharacterInstance characterInstance,float delta){
        Color hurtColor = characterInstance.getHurtColor();
        hurtColor.a=Math.max(0,hurtColor.a-delta*2f);
    }
}
